package pdd.d20210831.t1;

import java.util.Arrays;
import java.util.Scanner;

/**
 * <li style="color: red;">Prob</li>
 *
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li>
 *
 * @author habitplus
 * @since 2021-08-31 18:57
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int k = sc.nextInt();

            int[] a = new int[n];
            int[] b = new int[m];

            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }

            for (int i = 0; i < m; i++) {
                b[i] = sc.nextInt();
            }

            Arrays.sort(a);
            Arrays.sort(b);

            int j = 0;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                // 寻找与 a[i] 消除的 b[j]
                while (j < m && Math.abs(a[i] - b[j]) > k) {
                    j++;
                }

                if (j < m) { // 找到了 abs(a[i],b[j]) <= k;
                    ans++;
                } else {
                    break;
                }
            }
            System.out.println(ans);
        }
    }
}
